package me.obstsalat.guildera;

import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerChatEvent;

public class d_chat {
	
	private static guildera plugin;
	
	d_chat(guildera pl) {
		plugin = pl;
	}
	
	public boolean onPlayerChat(PlayerChatEvent chat) {
		Player ply = chat.getPlayer();
		String msg = chat.getMessage();
		if(!plugin.checkViableWorld(ply.getWorld())) {
			return false;
		}
		
		if(msg.startsWith(".dungeon create tower")) {
			chat.setCancelled(true);
			if(ply.isOp()) {
				if(!ply.getLocation().getWorld().getName().equals(plugin.overworld.getName())) {
					ply.sendMessage("You can't create a dungeon in this world.");
					return true;
				}
				ply.sendMessage("Creating tower dungeon at your current location.");
				if(msg.contains("1")) {
					structureLib.generateDungeon(ply.getLocation().getBlockX(), ply.getLocation().getBlockY(), ply.getLocation().getBlockZ(), structureLib.DUNGEONTYPE_TOWER, 1);
				} else if(msg.contains("2")) {
					structureLib.generateDungeon(ply.getLocation().getBlockX(), ply.getLocation().getBlockY(), ply.getLocation().getBlockZ(), structureLib.DUNGEONTYPE_TOWER, 2);
				} else if(msg.contains("3")) {
					structureLib.generateDungeon(ply.getLocation().getBlockX(), ply.getLocation().getBlockY(), ply.getLocation().getBlockZ(), structureLib.DUNGEONTYPE_TOWER, 3);
				} else if(msg.contains("4")) {
					structureLib.generateDungeon(ply.getLocation().getBlockX(), ply.getLocation().getBlockY(), ply.getLocation().getBlockZ(), structureLib.DUNGEONTYPE_TOWER, 4);
				}
			} else {
				ply.sendMessage("You don't have the permission to use this command.");
			}
		} else if(msg.startsWith(".dungeon create nether")) {
			chat.setCancelled(true);
			if(ply.isOp()) {
				if(!ply.getLocation().getWorld().getName().equals(plugin.overworld.getName())) {
					ply.sendMessage("You can't create a dungeon in this world.");
					return true;
				}
				ply.sendMessage("Creating tower dungeon at your current location.");
				if(msg.contains("1")) {
					structureLib.generateDungeon(ply.getLocation().getBlockX(), ply.getLocation().getBlockY(), ply.getLocation().getBlockZ(), structureLib.DUNGEONTYPE_NETHER, 1);
				} else if(msg.contains("2")) {
					structureLib.generateDungeon(ply.getLocation().getBlockX(), ply.getLocation().getBlockY(), ply.getLocation().getBlockZ(), structureLib.DUNGEONTYPE_NETHER, 2);
				} else if(msg.contains("3")) {
					structureLib.generateDungeon(ply.getLocation().getBlockX(), ply.getLocation().getBlockY(), ply.getLocation().getBlockZ(), structureLib.DUNGEONTYPE_NETHER, 3);
				} else if(msg.contains("4")) {
					structureLib.generateDungeon(ply.getLocation().getBlockX(), ply.getLocation().getBlockY(), ply.getLocation().getBlockZ(), structureLib.DUNGEONTYPE_NETHER, 4);
				}
			} else {
				ply.sendMessage("You don't have the permission to use this command.");
			}
		} else if(msg.startsWith(".dungeon refill")) {
			chat.setCancelled(true);
			if(ply.isOp()) {
				ply.sendMessage("Refilling the loot of all dungeons.");
				for(int i = 0; i < plugin.treasures.size(); i++) {
					structureLib.refreshLoot(plugin.treasures.get(i));
				}
				plugin.logger.info("[" + plugin.getDescription().getName() + "] Refreshed loot of all dungeons.");
			} else {
				ply.sendMessage("You don't have the permission to use this command.");
			}
		}
		return chat.isCancelled();
	}
}
